<?php

	$productId = $_GET['productId'];
	$units = $_GET['units'];
	$masmenos = $_GET['masmenos'];
	
	session_start()	;
	
	if (!isset($_SESSION["products"])) {
		$_SESSION["products"] = array();
	}
	
	$actual = 0;
	
	if (isset($_SESSION["products"][$productId]['units'])) { 
		$actual = $_SESSION["products"][$productId]['units'];
	}
	
	if ($masmenos == "mas") {
		$_SESSION["products"][$productId]['units'] = $units + $actual;
	} else {
		$_SESSION["products"][$productId]['units'] = $actual - $units;
		if ($actual < $units) {
			unset($_SESSION["products"][$productId]);
		} else {
			$_SESSION["products"][$productId]['units'] = $actual - $units;
			if ($_SESSION["products"][$productId]['units'] == 0) {
				unset($_SESSION["products"][$productId]);
			}
		}
	}
	
	
	if (isset($_SESSION["products"][$productId]) && !isset($_SESSION["products"][$productId]['service'])) {
		$_SESSION["products"][$productId]['service'] = 1;
	}
	
?>